//
//  MyView.m
//  ZBuffer
//
//  Created by 俞云康 on 1/22/16.
//  Copyright © 2016 yushroom. All rights reserved.
//

#import "MyView.h"
#include "Renderer.hpp"
#include "Timer.hpp"
#include "Math.hpp"
#include "Ray.hpp"
#include "Material.hpp"
#include "Shape.hpp"
#include "Scene.hpp"
#include "Renderer.hpp"
#include "Camera.hpp"
#include "Integrator.hpp"
#include "Log.hpp"
#include "Params.hpp"


@implementation MyView {
    //NSBitmapImageRep *rep;
    //unsigned int* pix;
}

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    NSLog(@"drawRect: %lf %lf", dirtyRect.size.width, dirtyRect.size.height);
    //unsigned int* pix = (unsigned int*)[self.rep bitmapData];
    if (self.rep == nil || (self.rep.size.width != dirtyRect.size.width || self.rep.size.height != dirtyRect.size.height)) {
        //Timer t2("init");
        //t2.begin();
        self.rep = nil;
        self.rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:dirtyRect];
        [self.rep setOpaque:true];
        [self.rep setAlpha:false];
        //pix = (unsigned int*)[self.rep bitmapData];
        //t2.end();
        //t2.print();
    }
    [self.rep drawInRect:dirtyRect];
}

//- (void)redraw
//{
//    [self setNeedsDisplay:YES];
//}

- (BOOL)acceptsFirstResponder {
    return YES;
}


@end
